import axios from 'axios'

export function getCurrentCity(callback) {
  const currentCity = JSON.parse(localStorage.getItem('current_city'))
  if (currentCity) {
    return callback(currentCity)
  } else {
    const myCity = new window.BMap.LocalCity()
    myCity.get(async (result) => {
      // const cityName = result.name
      //   console.log(result, 99)
      const res = await axios.get(
        `http://localhost:8080/area/info?name=${result.name}`
      )
      console.log(res)
      const { status, body } = res.data
      if (status === 200) {
        localStorage.setItem('current_city', JSON.stringify(body))

        callback(body)
      }
    })
  }
}
